<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
	
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		<script src="assets/scripts/ui/ui.dialog.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript">
		$(function() {
			$('.message').fadeIn("slow");
			$('.btn_regist').click(function(){
				if( confirm('登録してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			
			$('.btn_update').click(function(){
				if( confirm('更新してよろしいですか？') ){
					document.fm.mode.value = 'input';
					document.fm.submit();
				}
			});
			
			$('.btn_return').click(function(){
				location.href = "mmatrix_index.php?hist=2";
			});
			
			$("#block_cd").change(function(){
				document.fm.block_name.value = $("#block_cd").find("option:selected").text();
			});
			
			$("#local_cd").change(function(){
				document.fm.local_name.value = $("#local_cd").find("option:selected").text();
			});
			
			$("#year4").change(function(){
				doWeeks( $("#year4").val());
			});
			
			$("#week_cd").change(function(){
				doWeenBeginEnd() ;
			});
			
			$('.text_date').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd(D)'
			});
			
			doWeeks( $("#year4").val());
{{ if $forms.week_cd != '' }}
			setWeeKOption('{{ $forms.week_cd }}');
{{ else }}
			doWeenBeginEnd();
{{ /if }}
		});
		function setWeeKOption(weekid) {
			$('#week_cd option').each(function() {  
				var value = $(this).val(); 
				if (value.split("_")[0] == weekid) {
				    $('#week_cd').val(value );
				    doWeenBeginEnd();
				}
			});
		}
		
		function doWeenBeginEnd() {
			//alert($('#week_cd option:selected').val());
			var weekarr = $('#week_cd option:selected').val().split("_");
			var year = $("#year4").val() + "/";
			var dayNames = ['日', '月', '火', '水', '木', '金', '土'];
			
			var tmpDate =new Date($("#year4").val(),weekarr[1].substr(0,2)*1 -1 ,weekarr[1].substr(2,2));
			$("#week_date_begin").val( year + weekarr[1].substr(0,2) + "/" + weekarr[1].substr(2,2) + "(" + dayNames[tmpDate.getDay()]+ ")"  );
			var tmpDate =new Date($("#year4").val(),weekarr[2].substr(0,2)*1 -1 ,weekarr[2].substr(2,2));
			$("#week_date_end").val( year + weekarr[2].substr(0,2) + "/" + weekarr[2].substr(2,2) + "(" + dayNames[tmpDate.getDay()]+ ")"  );
			//$("#week_date_end").val($("#year4").val() + weekarr[2] );
		}
		
		function doWeeks(year){
			var date = new Date();
			date.setFullYear(year,0,1);
			var yearEndDate = new Date();
			yearEndDate.setFullYear(year,11,31);
			var weeks =0;
			var dateBegin = date ;
			
			//var tmpDate = new Date();
			var tmpMonth,tmpDate
			tmpMonth = date.getMonth()+1;
			tmpDate  = date.getDate();
			var strNowWeek =  tmpMonth +"月" + tmpDate + "日";
			var intNowMMDD =  (tmpMonth < 10 ? "0" + tmpMonth :  tmpMonth.toString()) + (tmpDate < 10 ? "0" + tmpDate :  tmpDate.toString()) ;
			var strEndWeek =  "";
			var intEndMMDD =  "";
			$("#week_cd").children().remove();
			var strWeeks;
			var strvalue;
			while (date < yearEndDate ) {
				date.setDate(date.getDate()+1); 
				if (date.getDay() == 6) {
					var tmpDate =new Date(date.getYear(),date.getMonth(),date.getDate()-1);	
					strWeeks = "第" + weeks + "週" ;
					tmpMonth   = tmpDate.getMonth()+1;
					tmpDate    = tmpDate.getDate();
					strEndWeek = tmpMonth  +"月" + tmpDate + "日";
					intEndMMDD = (tmpMonth < 10 ? "0" + tmpMonth :  tmpMonth.toString()) + (tmpDate < 10 ? "0" + tmpDate :  tmpDate.toString()) ;
					strvalue = weeks + "_"  + intNowMMDD + "_" + intEndMMDD  ;
					$("#week_cd").append("<option value='" + strvalue + "'>" + strWeeks + "( "+ strNowWeek + "～" + strEndWeek + " ) </option>");  
					
					dateBegin  = date;
					tmpMonth   = dateBegin.getMonth()+1;
					tmpDate    = dateBegin.getDate();
					strNowWeek = tmpMonth  +"月" + tmpDate + "日";
					intNowMMDD = (tmpMonth < 10 ? "0" + tmpMonth :  tmpMonth.toString()) + (tmpDate < 10 ? "0" + tmpDate :  tmpDate.toString()) ;
					weeks      = weeks  + 1
				}
			}
		}
		//fun(2012 );
		</script>
		
	</head>
	<body id="">
{{ $menu }}
{{ $logout }}
		<div id="container"><div class="wrapper">
			<h2>マトリックスマスター管理</h2>
			<ul class="submenu clearfix">
				<li><a href="mmatrix_index.php">マトリックス情報一覧</a></li>
				<li>マトリックス情報登録</li>
				<li><a href="mmatrix_import.php">CSV更新</a></li>
			</ul>
			<h3>マトリックス情報{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}{{ if $phase == 'complete' }}完了{{ /if }}</h3>
{{ if $phase == 'input' }}
			<p class="message">内容を確認し、{{ if $forms.id == '' }}登録{{ else }}更新{{ /if }}ボタンをクリックしてください。</p>
			<form name="fm" action="mmatrix_form.php" method="post">
				<table class="formTable">
					<tbody>
{{ if $forms.id != '' }}
						<tr>
							<th>更新日</th>
							<td>
								{{ $forms.u_time }}<input type="hidden" name="u_time" value="{{ $forms.u_time }}" />
							</td>
						</tr>
						<tr>
							<th>更新者</th>
							<td>
								{{ $forms.m_user_name }}
							</td>
						</tr>
						<tr>
							<th>ID</th>
							<td>
								{{ $forms.id }}
							</td>
						</tr>
{{ /if }}
						<tr>
							<th><span>※</span>年度</th>
							<td>
{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年{{ $err.year4 }}
							</td>
						</tr><tr>
							<th><span>※</span>週</th>
							<td>
{{ html_options id='week_cd' name='week_cd' options=$week  }}{{ $err.week_cd }}
&nbsp; 第<input type="text" name="week_seq" id="week_seq"  value="{{ $forms.week_seq }}" style="width:20px" />回 (年始年末場合使用するだけ、1,2等１桁数字で入力してください)
							</td>
						</tr><tr>
							<th><span>※</span>周期間</th>
							<td>
								<input type="text" name="week_date_begin" id="week_date_begin"  readonly="readonly" value="{{ $forms.week_date_begin }}" />{{ $err.week_date_begin }} ～
								<input type="text" name="week_date_end"   id="week_date_end"    readonly="readonly" value="{{ $forms.week_date_end }}" />{{ $err.week_date_end }}
							</td>
						</tr><tr>
							<th><span>※</span>折込日</th>
							<td>
								<input type="text" name="flier_date" class="text_date" value="{{ $forms.flier_date }}" />{{ $err.flier_date }}
							</td>
						</tr>
					</tbody>
				</table><br>
				■期間設定
				<table class="formTable"> <tbody>
						<tr>
							<td></td><th>対象</th><th>作業</th><th>開始</th><th>終了</th>
						</tr>
						<tr>
						<th rowspan="4" align="center" valign="middle">Draft</th>
						<td>販促</td><td>作成</td>
						<td>&nbsp;</td>
						<td><input type="text" name="draft_create_dt" class="text_date" value="{{ $forms.draft_create_dt }}" /> {{ html_options id='draft_create_t' class='hsel' name='draft_create_t' options=$hours selected=$forms.draft_create_t }}時{{ $err.draft_create_dt }}</td>
						</tr><tr>
						<td>営業</td><td>入力</td>
						<td><input type="text" name="draft_input_begin_dt" class="text_date" value="{{ $forms.draft_input_begin_dt }}" /> {{ html_options id='draft_input_begin_t' class='hsel' name='draft_input_begin_t' options=$hours selected=$forms.draft_input_begin_t }}時{{ $err.draft_input_begin_dt }}</td>
						<td><input type="text" name="draft_input_end_dt" class="text_date" value="{{ $forms.draft_input_end_dt }}" /> {{ html_options id='draft_input_end_t' class='hsel' name='draft_input_end_t' options=$hours selected=$forms.draft_input_end_t }}時{{ $err.draft_input_end_dt }}</td>
						</tr><tr>
						<td>販促</td><td>確認．修正</td>
						<td><input type="text" name="draft_modi_begin_dt" class="text_date" value="{{ $forms.draft_modi_begin_dt }}" /> {{ html_options id='draft_modi_begin_t' class='hsel' name='draft_modi_begin_t' options=$hours selected=$forms.draft_modi_begin_t }}時{{ $err.draft_modi_begin_dt }}</td>
						<td><input type="text" name="draft_modi_end_dt" class="text_date" value="{{ $forms.draft_modi_end_dt }}" /> {{ html_options id='draft_modi_end_t' class='hsel' name='draft_modi_end_t' options=$hours selected=$forms.draft_modi_end_t }}時{{ $err.draft_modi_end_dt }}</td>
						</tr><tr>
						<td>各折込.印刷会社様</td><td>手配</td>
						<td><input type="text" name="draft_publish_begin_dt" class="text_date" value="{{ $forms.draft_publish_begin_dt }}" /> {{ html_options id='draft_publish_begin_t' class='hsel' name='draft_publish_begin_t' options=$hours selected=$forms.draft_publish_begin_t }}時{{ $err.draft_publish_begin_dt }}</td>
						<td><input type="text" name="draft_publish_end_dt" class="text_date" value="{{ $forms.draft_publish_end_dt }}" /> {{ html_options id='draft_publish_end_t' class='hsel' name='draft_publish_end_t' options=$hours selected=$forms.draft_publish_end_t }}時{{ $err.draft_publish_end_dt }}</td>
						</tr><tr>
						<th rowspan="3" align="center" valign="middle">Final</th>
						<td>営業</td><td>入力</td>
						<td><input type="text" name="final_input_begin_dt" class="text_date" value="{{ $forms.final_input_begin_dt }}" /> {{ html_options id='final_input_begin_t' class='hsel' name='final_input_begin_t' options=$hours selected=$forms.final_input_begin_t }}時{{ $err.final_input_begin_dt }}</td>
						<td><input type="text" name="final_input_end_dt" class="text_date" value="{{ $forms.final_input_end_dt }}" /> {{ html_options id='final_input_end_t' class='hsel' name='final_input_end_t' options=$hours selected=$forms.final_input_end_t }}時{{ $err.final_input_end_dt }}</td>
						</tr><tr>
						<td>販促</td><td>確認．修正</td>
						<td><input type="text" name="final_modi_begin_dt" class="text_date" value="{{ $forms.final_modi_begin_dt }}" /> {{ html_options id='final_modi_begin_t' class='hsel' name='final_modi_begin_t' options=$hours selected=$forms.final_modi_begin_t }}時{{ $err.final_modi_begin_dt }}</td>
						<td><input type="text" name="final_modi_end_dt" class="text_date" value="{{ $forms.final_modi_end_dt }}" /> {{ html_options id='final_modi_end_t' class='hsel' name='final_modi_end_t' options=$hours selected=$forms.final_modi_end_t}}時{{ $err.final_modi_end_dt }}</td>
						</tr><tr>
						<td>各折込.印刷会社様</td><td>手配</td>
						<td><input type="text" name="final_publish_begin_dt" class="text_date" value="{{ $forms.final_publish_begin_dt }}" /> {{ html_options id='final_publish_begin_t' class='hsel' name='final_publish_begin_t' options=$hours selected=$forms.final_publish_begin_t }}時{{ $err.final_publish_begin_dt }}</td>
						<td>&nbsp;</td>
						</tr>
				</table>
				<p class="button">
{{ if $forms.id != '' }}
					<button type="button" class="btn_return" class="submit"><span>戻る</span></button>
					<button type="button" class="btn_update" class="submit"><span>更新</span></button>
{{ else }}
					<button type="button" class="btn_regist" class="submit"><span>登録</span></button>
{{ /if }}
				</p>
				<input type="hidden" name="id" value="{{ $forms.id }}" />
				<input type="hidden" name="mode" value="" />
			</form>
<div id="dialog" >
</div>
 
{{ /if }}

{{ if $phase == 'complete' }}
			<p class="message">{{ $message }}</p>
			<ul>
{{ if $forms.id != '' }}
				<li>>> <a href="mmatrix_index.php?hist=2">一覧ページに戻る</a></li>
{{ else }}
				<li>>> <a href="mmatrix_index.php">一覧ページに戻る</a></li>
{{ /if }}
				<li>>> <a href="mmatrix_form.php">新規登録</a></li>
{{ if $forms.id != '' }}
				<li>>> <a href="mmatrix_form.php?id={{ $forms.id }}">更新</a></li>
{{ /if }}
			</ul>
{{ /if }}

		</div></div>
		{{ $footer }}
	</body>
</html>